//
//  UserLoginVC.m
//  DefendHealth
//
//  Created by UNOHACHA on 17/2/18.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "UserLoginVC.h"
#import "RegestFirstStepViewController.h"
@interface UserLoginVC ()
{
    UIButton * _checkPassW;
    UITextField * _passwTF;
    UITextField * _phoneTF;
}
@end

@implementation UserLoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.TitleNav.text = @"登录";
    self.view.backgroundColor = kWhiteColor;
    
//    self.view.backgroundColor = [UIColor colorWithPatternImage:IMAGE(@"马天明好帅")];
//    [self loginViewInit];
    self.Nav.hidden = YES;
    [self initView];

}
-(void)initView{
    UIImageView *  bgImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    bgImg.image = IMAGE(@"马天明好帅");
    [self.view addSubview:bgImg];
    
    
    UIImageView * logoImg = [[UIImageView alloc]initWithFrame:CGRectMake(30, 132, 40, 40)];
    logoImg.image = IMAGE(@"y");
//    logoImg.backgroundColor = kWhiteColor;
    [bgImg addSubview:logoImg];
    
    UILabel * title = [ReduceCode creatLabelWithFrame:CGRectMake(30, kMaxY(logoImg.frame)+27, kScreenWidth-60, 21) title:@"欢迎来到Y·RUN" titleColor:kWhiteColor font:21 textAlignment:NSTextAlignmentLeft];
    title.font = [UIFont fontWithName:@"ArialRoundedMTBold" size:21];
    [bgImg addSubview:title];
    
    UITextField * phoneTf = [ReduceCode creatTextFieldWithFrame:CGRectMake(30, kMaxY(title.frame)+49, kScreenWidth-60, 40) PlaceHold:@"请输入您的手机号码" PlaceHoldColor:UIColorFromRGB(0x888888) btnTitleFont:12 btnBackgroundColor:kClearColor KeyboardType:UIKeyboardTypeNumberPad isCorner:NO];
    phoneTf.leftView = [UIView new];
    [self.view addSubview:phoneTf];
    UIView * leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 74, 40)];
    leftView.backgroundColor = kClearColor;
    UIButton * areaBtn = [UIButton creatBtnWithFrame:CGRectMake(0, 0, 63, 40) btnTitle:@"+86" btnTitleColor:kWhiteColor btnTitleFont:10 btnTagPrice:0 btnSetImage:IMAGE(@"trabge2_white") btnBackgroundColor:kClearColor isCorner:NO action:^(UIButton *button) {
        
    }];
    [areaBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
    [leftView addSubview:areaBtn];
    [ToolUtil createLine:10 superView:leftView lift:kMaxX(areaBtn.frame) width:1 hight:20 color:UIColorFromRGB(0x888888)];
    phoneTf.leftView = leftView;
    phoneTf.leftViewMode = UITextFieldViewModeAlways;
    phoneTf.layer.borderColor = UIColorFromRGB(0x888888).CGColor;
    phoneTf.layer.borderWidth = 1;
    _phoneTF = phoneTf;

    UITextField * passwTf = [ReduceCode creatTextFieldWithFrame:CGRectMake(30, kMaxY(phoneTf.frame)+10, kScreenWidth-60, 40) PlaceHold:@"请输入密码" PlaceHoldColor:UIColorFromRGB(0x888888) btnTitleFont:12 btnBackgroundColor:kClearColor KeyboardType:UIKeyboardTypeDefault isCorner:NO];

    
    
    passwTf.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 40)];
    passwTf.leftView.backgroundColor = kClearColor;
    passwTf.leftViewMode = UITextFieldViewModeAlways;
    
    passwTf.rightView = [UIView new];
    UIView * rightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 62, 40)];
    rightView.backgroundColor = kClearColor;
    UIImageView * eyesImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 22, 14)];
    eyesImg.image = IMAGE(@"white-eye");
    [rightView addSubview:eyesImg];
    UIButton * checkPassw = [ReduceCode creatBtnWithFrame:CGRectMake(0, 0, 62, 40) btnTitle:nil btnTitleColor:nil btnTitleFont:0 btnBackgroundColor:kClearColor backgroundImage:nil isCorner:NO];
    checkPassw.selected = NO;
    
    [checkPassw addTarget:self action:@selector(checkPassw:) forControlEvents:UIControlEventTouchUpInside];
    [rightView addSubview:checkPassw];
    passwTf.rightView = rightView;
    passwTf.rightViewMode = UITextFieldViewModeAlways;
    passwTf.layer.borderColor = UIColorFromRGB(0x888888).CGColor;
    passwTf.layer.borderWidth = 1;
    passwTf.secureTextEntry = YES;
    eyesImg.centerX = rightView.centerX;
    eyesImg.centerY = rightView.centerY;
    [self.view addSubview:passwTf];
    _passwTF = passwTf;
    _checkPassW = checkPassw;

    UIButton * loginBtn = [ReduceCode creatBtnWithFrame:CGRectMake(30, kMaxY(passwTf.frame)+10, kScreenWidth-60, 40) btnTitle:@"登录" btnTitleColor:UIColorFromRGB(0x888888) btnTitleFont:15 btnBackgroundColor:UIColorFromRGB(0x47495f) backgroundImage:nil isCorner:NO];
    [self.view addSubview:loginBtn];
    
    CGFloat registWidth  = [ToolUtil autoWidth:@"注册账号" width:500 height:13 num:13];
    UIButton * registBtn = [ReduceCode creatBtnWithFrame:CGRectMake(30, kMaxY(loginBtn.frame)+10, registWidth, 13) btnTitle:@"注册账号" btnTitleColor:UIColorFromRGB(0xb2b2b2) btnTitleFont:13 btnBackgroundColor:kClearColor backgroundImage:nil isCorner:NO];
    [registBtn addTarget:self action:@selector(registVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registBtn];
    
    CGFloat titleWidth = [ToolUtil autoWidth:@"社交账号一键登录" width:500 height:10 num:10];
    UILabel * sanfL = [ReduceCode creatLabelWithFrame:CGRectMake(0, kMaxY(registBtn.frame)+94, titleWidth+20, 10) title:@"社交账号一键登录" titleColor:UIColorFromRGB(0x9b9b9b) font:10 textAlignment:NSTextAlignmentCenter];
    if (kScreenWidth == 320) {
        sanfL.frame = CGRectMake(0, kMaxY(registBtn.frame)+54, titleWidth+20, 10);
    }
    sanfL.centerX = self.view.centerX;
    sanfL.backgroundColor = kClearColor;
    
    [bgImg addSubview:sanfL];
    
    
    UIView * linView  = [[UIView alloc]initWithFrame:CGRectMake(self.view.centerX-(titleWidth+20)/2-10, 0, 10, 1)];
    linView.backgroundColor = UIColorFromRGB(0xbcbcbc);
    linView.centerY = sanfL.centerY;
    [bgImg addSubview:linView];
    UIView * linView2  = [[UIView alloc]initWithFrame:CGRectMake(self.view.centerX+(titleWidth+20)/2, 0, 10, 1)];
    linView2.backgroundColor = UIColorFromRGB(0xbcbcbc);
    linView2.centerY = sanfL.centerY;
    [bgImg addSubview:linView2];
    
    
    
    CGFloat  weight = (kScreenWidth-27*3)/4;
    NSArray * imgArr = @[@"wechat",@"qq",@"sina"];
    for (int B = 0; B<3; B++) {
        
        UIButton * shareBtn = [UIButton creatBtnWithFrame:CGRectMake((B+1)*weight+B*27, kMaxY(sanfL.frame)+15, 27, 27) btnTitle:@"" btnTitleColor:kWhiteColor btnTitleFont:18 btnTagPrice:0 btnSetImage:nil btnBackgroundColor:nil isCorner:YES action:^(UIButton *button) {
            
            
        }];
        [shareBtn setBackgroundImage:IMAGE(imgArr[B]) forState:UIControlStateNormal];
        shareBtn.layer.cornerRadius = shareBtn.width/2;
        [bgImg addSubview:shareBtn];
    }
}
-(void)registVC{
    RegestFirstStepViewController *stVC = [RegestFirstStepViewController new];
    stVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:stVC animated:YES];
}
-(void)loginViewInit {
    
    
    UIImageView * loginImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(0, 10, 100, 100) imageName:@"" isCorner:YES];
    loginImg.backgroundColor = [UIColor grayColor];
    loginImg.centerX = self.view.centerX;
    loginImg.y = k_NavigationHeight+10;
    [self.view addSubview:loginImg];
    
    
    
    
    UIImageView * nameImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(62.5, kMaxY(loginImg.frame)+45, 27, 27) imageName:@"" isCorner:YES];
    nameImg.backgroundColor = [UIColor grayColor];
    [self.view addSubview:nameImg];
    
    
    UITextField * userName  = [ReduceCode creatTextFieldWithFrame:CGRectMake(kMaxX(nameImg.frame)+12, 0, kScreenWidth-kMaxX(nameImg.frame)*2-20, 16) PlaceHold:@"请输入手机号码" PlaceHoldColor:UIColorFromRGB(0x999999) btnTitleFont:16 btnBackgroundColor:nil KeyboardType:UIKeyboardTypeDefault isCorner:NO];
    userName.centerY = nameImg.centerY;
    [self.view addSubview:userName];
    
    
    
    

    UIView * loginLin  = [[UIView alloc]initWithFrame:CGRectMake(0, kMaxY(nameImg.frame)+17, kScreenWidth-130, 1)];
    loginLin.backgroundColor = UIColorFromRGB(0xbcbcbc);
    loginLin.centerX = loginImg.centerX;
    [self.view addSubview:loginLin];

    
 
    
    UIImageView * passImg = [ReduceCode creatImageVeiwWithFrame:CGRectMake(62.5, kMaxY(nameImg.frame)+34, 27, 27) imageName:@"" isCorner:YES];
    passImg.backgroundColor = [UIColor grayColor];
    
    [self.view addSubview:passImg];
   
    UITextField * userPass  = [ReduceCode creatTextFieldWithFrame:CGRectMake(kMaxX(passImg.frame)+12, 0, kScreenWidth-kMaxX(nameImg.frame)*2-20, 16) PlaceHold:@"请输入密码" PlaceHoldColor:UIColorFromRGB(0x999999) btnTitleFont:16 btnBackgroundColor:nil KeyboardType:UIKeyboardTypeDefault isCorner:NO];
    userPass.centerY = passImg.centerY;
    [self.view addSubview:userPass];
    
    
    UIButton * loginBtn = [UIButton creatBtnWithFrame:CGRectMake(0, kMaxY(passImg.frame)+30, kScreenWidth-100, 40) btnTitle:@"登录" btnTitleColor:kWhiteColor btnTitleFont:18 btnTagPrice:0 btnSetImage:nil btnBackgroundColor:UIColorFromRGB(0x7b7c7c) isCorner:YES action:^(UIButton *button) {
        
        
    }];
    loginBtn.layer.cornerRadius = 20;
    loginBtn.centerX = loginImg.centerX;
    [self.view addSubview:loginBtn];
    
    UIButton * registerBtn = [UIButton creatBtnWithFrame:CGRectMake(0, kMaxY(loginBtn.frame)+20, kScreenWidth-100, 40) btnTitle:@"注册" btnTitleColor:kWhiteColor btnTitleFont:18 btnTagPrice:0 btnSetImage:nil btnBackgroundColor:UIColorFromRGB(0xbababa) isCorner:YES action:^(UIButton *button) {
        RegestFirstStepViewController *stVC = [RegestFirstStepViewController new];
        stVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:stVC animated:YES];
        
    }];
    registerBtn.layer.cornerRadius = 20;
    registerBtn.centerX = loginImg.centerX;
    [self.view addSubview:registerBtn];
    

    UILabel * sanfL = [ReduceCode creatLabelWithFrame:CGRectMake(0, kMaxY(registerBtn.frame)+30, 110, 14) title:@"第三方登录" titleColor:UIColorFromRGB(0x9b9b9b) font:14 textAlignment:NSTextAlignmentCenter];
    sanfL.centerX = loginImg.centerX;
    sanfL.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:sanfL];
    
    UIView * linView  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth-125, 1)];
    linView.backgroundColor = UIColorFromRGB(0xbcbcbc);
    linView.centerX = loginImg.centerX;
    linView.centerY = sanfL.centerY;
    [self.view addSubview:linView];
    
    [self.view bringSubviewToFront:sanfL];
    
    
    CGFloat  weight = (kScreenWidth-27*3)/4;
    
    for (int B = 0; B<3; B++) {
        
        UIButton * shareBtn = [UIButton creatBtnWithFrame:CGRectMake((B+1)*weight+B*27, kMaxY(sanfL.frame)+20, 27, 27) btnTitle:@"" btnTitleColor:kWhiteColor btnTitleFont:18 btnTagPrice:0 btnSetImage:nil btnBackgroundColor:UIColorFromRGB(0xbababa) isCorner:YES action:^(UIButton *button) {
            
            
        }];
        shareBtn.layer.cornerRadius = shareBtn.width/2;
        [self.view addSubview:shareBtn];
        
        
    }
    
    
    
}
-(void)checkPassw:(UIButton *)sent{
    sent.selected=!sent.selected;
    if (sent.tag==_checkPassW.tag) {
        if (sent.selected) {
            _checkPassW.selected=YES;
            [_checkPassW setBackgroundImage:IMAGE(@"") forState:UIControlStateSelected];
//            img.image=IMAGE(@"ic_xianshimima_li");
            _passwTF.secureTextEntry=NO;
            NSString * str=_passwTF.text;
            _passwTF.text=@"";
            _passwTF.text=str;
        }else{
            _checkPassW.selected=NO;
//            img.image=IMAGE(@"ic_xianshimima_nor");
            [_checkPassW setBackgroundImage:IMAGE(@"") forState:UIControlStateNormal];

            _passwTF.secureTextEntry=YES;
            
        }
    }
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    
    [self.view endEditing:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
